package com.cw.jeeyt.service.converter.security;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.security.SecurityOrgUserBo;
import com.cw.jeeyt.dao.model.security.SecurityOrgUserDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 机构用户信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:01:34
 */
public class SecurityOrgUserConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SecurityOrgUserBo do2Bo(SecurityOrgUserDo model) {
        if (model == null) {
            return null;
        }
        SecurityOrgUserBo bo = new SecurityOrgUserBo();
        bo.setId(model.getId());
        bo.setOrgId(model.getOrgId());
        bo.setOrgName(model.getOrgName());
        bo.setUserId(model.getUserId());
        bo.setUserName(model.getUserName());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SecurityOrgUserDo bo2Do(SecurityOrgUserBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityOrgUserDo model = new SecurityOrgUserDo();
        model.setId(bo.getId());
        model.setOrgId(bo.getOrgId());
        model.setOrgName(bo.getOrgName());
        model.setUserId(bo.getUserId());
        model.setUserName(bo.getUserName());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SecurityOrgUserBo> doList2BoList(List<SecurityOrgUserDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityOrgUserConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SecurityOrgUserDo> boList2DoList(List<SecurityOrgUserBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityOrgUserConverter::bo2Do));
    }
}